package com.tencent.sr.iris.basic.saas.service.util;

import com.tencent.sr.iris.basic.saas.common.enums.AssessmentThresholdTypeEnum;
import com.tencent.sr.iris.basic.saas.common.enums.IrisTaskTypeEnum;
import com.tencent.sr.iris.basic.saas.service.model.GroupTaskBoardSaleNumSprintExportInfo;
import com.tencent.sr.iris.basic.saas.service.model.GroupTaskBoardSprintBaseExportInfo;
import com.tencent.sr.iris.basic.saas.service.model.GroupTaskBoardSprintExportInfo;
import com.tencent.sr.iris.basic.saas.service.model.advisor.*;
import lombok.extern.slf4j.Slf4j;

/**
 * 导师团长任务工具类
 *
 * @author nixiaolin
 * @date 2023/2/8 11:39
 */
@Slf4j
public abstract class AdvisorBoardUtils {


    /**
     * 创建GMV冲刺赛/销量冲刺赛导出实体
     *
     * @param taskTargetEvaluation
     * @param taskPhaseRuleAssessmentThresholdType
     * @return
     */
    public static AdvisorBoardSprintExportInfo newOperateBoardSprintExportInfo(Integer taskTargetEvaluation, Integer taskPhaseRuleAssessmentThresholdType) {
        Class<? extends AdvisorBoardSprintExportInfo> exportClass = getExportClass(taskTargetEvaluation, taskPhaseRuleAssessmentThresholdType);
        try {
            return exportClass.newInstance();
        } catch (Exception e) {
            return new AdvisorBoardSprintExportInfo();
        }
    }

    /**
     * 创建GMV冲刺赛/销量冲刺赛导出Class对象
     *
     * @param taskTargetEvaluation
     * @param taskPhaseRuleAssessmentThresholdType
     * @return
     */
    public static Class<? extends AdvisorBoardSprintExportInfo> getExportClass(Integer taskTargetEvaluation, Integer taskPhaseRuleAssessmentThresholdType) {
        AssessmentThresholdTypeEnum typeEnum = AssessmentThresholdTypeEnum.getEnumByCode(taskPhaseRuleAssessmentThresholdType);
        if (typeEnum == null) {
            IrisTaskTypeEnum taskTypeEnum = IrisTaskTypeEnum.getEnumByType(taskTargetEvaluation);
            if (taskTypeEnum == null) {
                return AdvisorBoardSalesSprintExportInfo.class;
            }

            switch (taskTypeEnum) {
                case GMV_SPRINT:
                case GMV_SPRINT_MAGNIFY:
                    return AdvisorBoardGmvSprintExportInfo.class;
                case SALE_SPRINT:
                case NEW_SALE_SPRINT:
                    return AdvisorBoardSaleNumSprintExportInfo.class;
                default:
                    return AdvisorBoardSalesSprintExportInfo.class;
            }
        }

        switch (typeEnum) {
            case SALE_NUM:
                return AdvisorBoardSalesSprintExportInfo.class;
            case DISTRIBUTION_ORDER_NUM:
                return AdvisorBoardDistributionSprintExportInfo.class;
            default:
                return AdvisorBoardSprintExportInfo.class;
        }
    }

    /**
     * 多目标冲刺赛导出Class对象
     *
     * @param taskTargetEvaluation
     * @return
     */
    public static Class<? extends GroupTaskBoardSprintBaseExportInfo> getGroupTaskBoardSprintClass(Integer taskTargetEvaluation) {
        IrisTaskTypeEnum taskTypeEnum = IrisTaskTypeEnum.getEnumByType(taskTargetEvaluation);
        if (taskTypeEnum == null) {
            return GroupTaskBoardSprintBaseExportInfo.class;
        }

        switch (taskTypeEnum) {
            case SALE_SPRINT:
            case NEW_SALE_SPRINT:
                return GroupTaskBoardSaleNumSprintExportInfo.class;
            default:
                log.error("任务类型错误，返回默认类型GroupTaskBoardSprintExportInfo");
                return GroupTaskBoardSprintExportInfo.class;
        }
    }

    public static GroupTaskBoardSprintBaseExportInfo newGroupTaskBoardSprintExportInfo(Integer taskTargetEvaluation) {
        Class<? extends GroupTaskBoardSprintBaseExportInfo> exportClass = getGroupTaskBoardSprintClass(taskTargetEvaluation);
        try {
            return exportClass.newInstance();
        } catch (Exception e) {
            log.error("实例化导出实体错误：", e);
            return new GroupTaskBoardSprintExportInfo();
        }
    }
}
